package com.whw.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.whw.entity.Student;

@RestController
@RequestMapping("/student")
public class StudentConsumerController {
	
	@Resource
	private RestTemplate restTemplate;
	
	private static final String URL_PRIFIXX="http://MICROSERVICE-SUDENT/student";
	
	@PostMapping("/save")
	public boolean save(Student student){
		return restTemplate.postForObject(URL_PRIFIXX+"/save", student, Boolean.class);
	}
	
	@SuppressWarnings("unchecked")
	@GetMapping("/list")
	public Map<String, Object>list(){
		return restTemplate.getForObject(URL_PRIFIXX+"/list", Map.class);
	}
	
	@GetMapping("/get/{id}")
	public Student get(@PathVariable("id")Integer id){
		return restTemplate.getForObject(URL_PRIFIXX+"/get/"+id, Student.class);
	}
	
	@GetMapping("/delete/{id}")
	public boolean delete(@PathVariable Integer id){
		return restTemplate.getForObject(URL_PRIFIXX+"/delete/"+id, Boolean.class);
	}
	
	@SuppressWarnings("unchecked")
	@GetMapping("/getInfo")
	public Map<String, Object> getInfo(){
		return restTemplate.getForObject(URL_PRIFIXX+"/getInfo", Map.class);
	}
	
}
